package com.zhu.reflex;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhujiabao
 * @Date: 2023/05/23/19:32
 * @Description:
 */
public class MyReflexDemo {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {


        /**
         * 获取c1ass对象的三种方式：
         * 1.Class.forName("全类名")；
         * 2.类名.c1ass
         * 3.对象.getclass();
         */

        Class clazz1 = Class.forName("com.zhu.reflex.Student");

        Class clazz2 = Student.class;

        Student student = new Student();
        Class clazz3 = student.getClass();

//        System.out.println(clazz1);
//        System.out.println(clazz1 == clazz2);
//        System.out.println(clazz3 == clazz2);



        // 获取构造方法
        Constructor[] constructors = clazz1.getConstructors();
        Arrays.stream(constructors).forEach((constructor) -> System.out.println(constructor));
        Constructor[] constructors2 = clazz1.getDeclaredConstructors();
        Arrays.stream(constructors2).forEach((constructor) -> System.out.println(constructor));
        Constructor constructor1 = clazz1.getConstructor();
        Constructor constructor2 = clazz1.getConstructor(String.class);
        Constructor constructor3 = clazz1.getConstructor(Integer.class);
        Constructor constructor4 = clazz1.getDeclaredConstructor(String.class,Integer.class);
        System.out.println(constructor1);
        System.out.println(constructor2);
        System.out.println(constructor3);
        System.out.println(constructor4);



    }



}
